package com.dragon.www.haier.popupwindow;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;

import com.dragon.www.haier.R;
import com.dragon.www.haier.activity.MainActivity;
import com.dragon.www.haier.adapter.CurtainAdapter;

/**
 * Created by 51268 on 2016/3/13.
 */
public class CurtainPopWindow extends BasePopupWindow{

    /*
    窗帘popwindow上的返回
     */
    private ImageView imageBackCurtain;

    private final static int curtainPopBackgroundColor=0xD9BC1F46;

    /*
    构造函数初始化
     */
    public CurtainPopWindow(Context context) {
        super(context);
    }

    /*
    显示popwindow，并且注册点击事件
     */
    public void showPopWindow(View view ,int xOffsetToView, int yOffsetToView) {
        contentView = LayoutInflater.from(context).inflate(R.layout.curtain_view, null);
        super.showPopWindow(view, xOffsetToView, yOffsetToView);

        bindAdapter(contentView);

        this.setBackgroundDrawable(new BitmapDrawable());
        //显示
        GradientDrawable myGrad = (GradientDrawable)contentView.getBackground();
        myGrad.setColor(curtainPopBackgroundColor);

        imageBackCurtain = (ImageView) contentView.findViewById(R.id.image_back_curtain);

        imageBackCurtain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    public void bindAdapter(View view) {
        gview = (GridView) view.findViewById(R.id.gview);
        mAdapter = new CurtainAdapter(context);
        mAdapter.setData(getData(MainActivity.TYPE_CURTAIN));
        gview.setAdapter(mAdapter);
    }
}


